#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int n,m;
int flip=0;
char a[305];
char s[305][305];
inline int id(int x,int y){
    return (x-1)*m+y;
}
int f[305][300000];
void add(int &x,int y){
    x+=y;
    if(x>=mod)x-=mod;
}
int ans[305][305];
int main(){
    freopen("disanti.in","r",stdin);
    freopen("disanti.out","w",stdout);
    scanf("%d%d",&n,&m);
    if(n<m){
        swap(n,m);
        flip=1;
    }
    if(flip){
        for(int i=1;i<=m;i++)scanf("%s",s[i]+1);
        for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)a[id(i,j)]=s[j][i];
    }
    else{
        for(int i=1;i<=n;i++)scanf("%s",a+1+(i-1)*m);
    }
    int F=(2<<m)-1;
    for(int sx=1;sx<=n;sx++){
        for(int sy=1;sy<=m;sy++){
            a[id(sx,sy)]^=1;
            for(int i=0;i<=n*m;i++)for(int j=0;j<(2<<m);j++)f[i][j]=0;
            f[0][0]=1;
            for(int i=0;i<n*m;i++)for(int j=0;j<(2<<m);j++){
                int val=f[i][j];
                if(!val)continue;
                // printf("f[%d][%d]=%d\n",i,j,f[i][j]);
                int x=i/m;
                int y=i-x*m;
                int nj,fj=(y==0?(j<<1):j)&F;
                // printf("%d %d\n",x,y);
                nj=fj&(F-(3<<y));
                // printf("%d %d\n",nj,fj);
                // horizontal
                if(((1<<y)&fj) && a[i+1]==a[i]){
                    add(f[i+1][(nj+(2<<y))&(F^(1<<(y-1)))],val);
                }
                // vertical
                // printf("%d %d %d\n",a[i+1],a[i+1-m],(2<<y));
                if(((2<<y)&fj) && a[i+1]==a[i+1-m]){
                    // printf("to %d\n",nj+(1<<y));
                    add(f[i+1][nj+(1<<y)],val);
                }
                // new
                // printf("to %d\n",nj+(3<<y));
                add(f[i+1][nj+(3<<y)],val);
            }
            int sum=0;
            for(int i=0;i<(2<<m);i++)add(sum,f[n*m][i]);
            if(flip)ans[sy][sx]=sum;
            else ans[sx][sy]=sum;
            a[id(sx,sy)]^=1;
        }
    }
    if(flip){
        for(int i=1;i<=m;i++){
            for(int j=1;j<=n;j++)printf("%d ",ans[i][j]);
            printf("\n");
        }
    }
    else{
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++)printf("%d ",ans[i][j]);
            printf("\n");
        }
    }
    return 0;
}